package org.esk.dablog.model;

import javax.persistence.*;
import java.util.Date;

/**
 * This class
 * User: jc
 * Date: 22.11.2006
 * Time: 10:39:03
 * $Id:$
 *
 * @hibernate.class table="COMMENTS"
 * lazy="true"
 * discriminator-value="0"
 * @hibernate.discriminator column="COMMENT_TYPE"
 * type="integer"
 */
@Entity
@Table(name = "COMMENTS")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "COMMENT_TYPE", discriminatorType = DiscriminatorType.INTEGER)
@DiscriminatorValue("0")
public class Comment {

    private long id;
    private int type;
    private int state;
    private String text;
    private Date date;
    private String ip;
    private String anonymousName;
    private boolean anonymous;
    private Author author;
    private Entry entry;
    private Comment parent;


    /**
     * @return
     * @hibernate.id column="ID"
     * generator-class="native"
     * @hibernate.generator-param name="sequence"
     * value="SEQ_COMMENTS"
     */
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_COMMENTS")
    @SequenceGenerator(name = "SEQ_COMMENTS", sequenceName = "seq_comments")
    @Column(name = "ID")
    public long getId() {
        return id;
    }

    /**
     * @return
     * @hibernate.property column="TEXT"
     */
    @Column(name = "TEXT")
    public String getText() {
        return text;
    }

    /**
     * @return
     * @hibernate.property column="COMMENT_DATE"
     */
    @Column(name = "COMMENT_DATE")
    public Date getDate() {
        return date;
    }

    /**
     * @return
     * @hibernate.property column="IP_ADDRESS"
     */
    @Column(name = "IP_ADDRESS")
    public String getIp() {
        return ip;
    }

    /**
     * @return
     * @hibernate.property column="ANONYMOUS_NAME"
     */
    @Column(name = "ANONYMOUS_NAME")
    public String getAnonymousName() {
        return anonymousName;
    }

    /**
     * @return
     * @hibernate.property column="IS_ANONYMOUS"
     */
    @Column(name = "IS_ANONYMOUS")
    public boolean isAnonymous() {
        return anonymous;
    }

    /**
     * @return
     * @hibernate.many-to-one column="AUTHOR_ID"
     */
    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    @JoinColumn(name = "AUTHOR_ID")
    public Author getAuthor() {
        return author;
    }

    /**
     * @return
     * @hibernate.many-to-one column="ENTRY_ID"
     * not-null="true"
     * foreign-key="FK_COMMENT_ENTRY"
     */
    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    @JoinColumn(name = "ENTRY_ID")
    public Entry getEntry() {
        return entry;
    }


    /**
     * @return
     * @hibernate.property column="COMMENT_TYPE"
     * insert="false"
     * update="false"
     */
    @Column(name="COMMENT_TYPE", insertable=false, updatable=false)
    public int getType() {
        return type;
    }


    /**
     * @return
     * @hibernate.many-to-one column="PARENT_COMMENT_ID"
     */
    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    @JoinColumn(name = "PARENT_COMMENT_ID")
    public Comment getParent() {
        return parent;
    }


    /**
     * @hibernate.property column="STATE"
     */
    @Column(name="STATE")
    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public void setParent(Comment parent) {
        this.parent = parent;
    }

    public void setType(int type) {
        this.type = type;
    }

    public void setId(long id) {
        this.id = id;
    }

    public void setText(String text) {
        this.text = text;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public void setAnonymousName(String anonymousName) {
        this.anonymousName = anonymousName;
    }

    public void setAnonymous(boolean anonymous) {
        this.anonymous = anonymous;
    }

    public void setAuthor(Author author) {
        this.author = author;
    }

    public void setEntry(Entry entry) {
        this.entry = entry;
    }
}
